package com.wjl.springcloudalibaba.sentinel.gatewaysentinel.service;

import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.wjl.springcloudalibaba.sentinel.gatewaysentinel.fallback.HelloFallback;
import com.wjl.springcloudalibaba.sentinel.gatewaysentinel.handler.HelloBlockHandler;
import org.springframework.stereotype.Service;

/**
 * @author wjl
 */
@Service
public class HelloServiceImpl implements HelloService {
    @Override
    @SentinelResource(value = "hello",
            entryType = EntryType.OUT,
            blockHandler = "blockHelloHandler",
            blockHandlerClass = HelloBlockHandler.class,
            fallback = "helloFallback",
            fallbackClass = HelloFallback.class
    )
    public String hello() {
        if (System.currentTimeMillis() % 2L == 0) {
            throw new IllegalArgumentException("mock exception");
        }
        return "Hello Sentinel";
    }
}
